package com.ruoyi.demo.controller;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@RestController
public class  FileUploadController {

    @PostMapping("/demo/upload")
    public String handleFileUpload(@RequestParam("file") MultipartFile file) {
        if (file.isEmpty()) {
            return "文件为空";
        }

        try {
            // 保存文件到指定路径
            String filePath = "/path/to/save/" + file.getOriginalFilename();
            file.transferTo(new File(filePath));
            System.out.println("文件上传成功: " + filePath);
            return "文件上传成功: " + filePath;
        } catch (IOException e) {
            e.printStackTrace();
            return "文件上传失败";
        }
    }
}
